﻿using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;

namespace CoreLims.Middleware
{
    /// <summary>
    /// 获得登录用户的IP地址
    /// </summary>
    public class GetIPAddress
    {
        private readonly RequestDelegate _next; //注意，单例编程模式。中间件都应该采用这种模式。

        public GetIPAddress(RequestDelegate next)
        {
            _next = next;
        }

        public async Task Invoke(HttpContext context)
        {
            await context.Response.WriteAsync(context.Connection.RemoteIpAddress.ToString());
            await _next(context);
        }
    }
}
